// 获取URL地址参数
function getQueryString(name, url) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    if (!url || url == ""){
	    url = window.location.search;
    }else{	
    	url = url.substring(url.indexOf("?"));
    }
    r = url.substr(1).match(reg)
    if (r != null) return unescape(r[2]); return null;
}

/**
 * @Description: 使用ajax分页
 * @author 于辉
 * @date 2017年01月13日
 *
 */
function paginationMothod (pageNo,pageSize,url,listName,searchParam) {
	$.post(url+"?pageNo="+pageNo+"&pageSize="+pageSize+searchParam, "", function(result) {
		var listHtml = result[listName];
		var pageHtml = result["page"];
		$("#listHtml").html(listHtml);
		$("#paging").html(pageHtml);
		if ($("#pageNum") != undefined) {
			$("#pageNum").val(pageNo);
		}
	}, 'json');
}
//AJAX 返回HTML
function callBackHtml(result){
	
	var dv = document.createElement("span");
	dv.innerHTML = result;
	return dv;
	
}

//去掉表单格式化
function formUnFormat(t){
	
	$(t).find("input[type='tel']").each(function(i,e){
		var v=$(e).val().trim();
	    $(e).val(v.replace(/[^\d\.-]/g, ""));
	});
	
}

//去掉表单格式化
function unFormat(e){
	var v=$(e).val().trim();
	$(e).val(v.replace(/[^\d\.-]/g, ""));
	var s=$(e).val();
	var numberVerification = /^[0-9]+.?[0-9]*$/;   
    if (numberVerification.test($(e).val())){
    	var l = s.split(".")[0], r = s.split(".")[1];  
    	if(parseFloat(r)==0){
    		$(e).val(l);
    	}
    }
}

//格式化金额
function formatMoney(e, n) {  
	var s=$(e).val().replace(",","").trim();
	//判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/  
	var numberVerification = /^[0-9]+.?[0-9]*$/;   
    if (numberVerification.test(s)){
    	n = n > 0 && n <= 20 ? n : 2;  
        s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";  
        var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];  
        t = "";  
        for (var i = 0; i < l.length; i++) {  
            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
        } 
        $(e).val(t.split("").reverse().join("") + "." + r);
    }else{
    	$(e).val("");
    }
}  

//格式化数字
function formatNumber(e) {  
	var s=$(e).val().replace(",","").trim();
	//判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/  
	var numberVerification = /^[0-9]+.?[0-9]*$/;   
    if (numberVerification.test(s)){
    s = (s + "").replace(/[^\d\.-]/g, "")+ "";  
   
    var l = s.split(".")[0].split("").reverse(),r = s.split(".")[1];
    t = "";  
    for (var i = 0; i < l.length; i++) {  
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
    } 
    var val="";
    if(typeof(r)!="undefined" &&  r!="undefined" ){
    	val="." + r;
    }
    $(e).val(t.split("").reverse().join("")+val);
    }else{
    	$(e).val("");
    }
}

//取得系统当前时间
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}

//日期格式化
function getMoth(dateVal) {
	   var newDate = new Date(dateVal);
	   var sMonth = padValue(newDate.getMonth() + 1);
	   var sDay = padValue(newDate.getDate());
	   var sYear = newDate.getFullYear();
     return sYear+'-'+sMonth+'-'+sDay;
 }
function padValue(value) {
	   return (value < 10) ? "0" + value : value;
}
// 去前后空格
function trim(t){
	 return (t||"").replace(/^\s+|\s+$/g, "");
}
//格式化文本数字
function formatNumberText(e) {  
	var s=$(e).text().replace(",","").trim();
	//判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/  
	var numberVerification = /^[0-9]+.?[0-9]*$/;   
    if (numberVerification.test(s)){
    s = (s + "").replace(/[^\d\.-]/g, "")+ "";  
   
    var l = s.split(".")[0].split("").reverse(),r = s.split(".")[1];
    t = "";  
    for (var i = 0; i < l.length; i++) {  
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
    } 
    var val="";
    if(typeof(r)!="undefined" &&  r!="undefined" ){
    	val="." + r;
    }
    $(e).text(t.split("").reverse().join("")+val);
    }else{
    	$(e).text("");
    }
}
//格式化文本金额
function formatMoneyText(e, n) {  
	var s=$(e).text().replace(",","").trim();
	//判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/  
	var numberVerification = /^[0-9]+.?[0-9]*$/;   
    if (numberVerification.test(s)){
    	n = n > 0 && n <= 20 ? n : 2;  
        s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";  
        var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];  
        t = "";  
        for (var i = 0; i < l.length; i++) {  
            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
        } 
        $(e).text(t.split("").reverse().join("") + "." + r);
    }else{
    	$(e).text("");
    }
}  
//去掉表单文本格式化
function unFormatText(e){
	var v=$(e).text().trim();
	$(e).text(v.replace(/[^\d\.-]/g, ""));
	var s=$(e).text();
	var numberVerification = /^[0-9]+.?[0-9]*$/;   
    if (numberVerification.test($(e).text())){
    	var l = s.split(".")[0], r = s.split(".")[1];  
    	if(parseFloat(r)==0){
    		$(e).text(l);
    	}
    }
}

//----------------------------------------------- 日 期 入 力 --------------------------------------------------------------------//

/* 日期  */
var dateFmt;
/**
 * 检验日期格式是否正确 ，如果格式正确，检验该日期是否为正确日期
 * 要求格式：yyyy-MM-dd 或  yyyyMMdd
 * @param dateValue
 * @returns {Boolean}
 */
function DATECHECK(dateValue) {
    var date = dateValue;
    var result1 = date.match(/^(\d{4})(-)(\d{2})\2(\d{2})$/);
	var result2 = date.match(/^(\d{4})(\d{2})(\d{2})$/);
	var d;
    if (result1 != null){
    	d = new Date(result1[1], result1[3] - 1, result1[4]);
    	dateFmt = d;
    	return (d.getFullYear() == result1[1] && (d.getMonth() + 1) == result1[3] && d.getDate() == result1[4]);
    } else if(result2 != null){
    	d = new Date(result2[1], result2[2] - 1, result2[3]);
    	dateFmt = d;
    	return (d.getFullYear() == result2[1] && (d.getMonth() + 1) == result2[2] && d.getDate() == result2[3]);
    }
    return false;
}
/**
 * 
 * @param obj
 * @returns {Boolean}
 */
function CheckDate(obj) {
    var ret = true;
    if (obj.value == "") {
    	ret = false;
    }else if (!DATECHECK(obj.value)) {
        alert("请输入正确的日期，日期格式yyyy-MM-dd或yyyyMMdd");
        obj.value = "";
        ret = false;
    }else{
    	obj.value = dateFormat("yyyy-MM-dd", dateFmt);
    }
    return ret;
}
/**
 * 格式化日期
 * @param str
 * @param d
 * @returns
 */
function dateFormat(str,d) {    
	if( checkNull(str)){  //如果格式化字符为空，返回空字符    
	        return "";      
	}  
	if(checkNull(d)){  //如果日期为空，自动获取当前日期    
	    d=new Date();      
	}else if(d.constructor!=Date){//如果参数不是一个日期对象，就认为是一个标准Long值日期  
	    d=new Date(d);  
	}  
	 return  str.replace("yyyy",d.getFullYear()).replace("MM",fillZero(d.getMonth()+1)).replace("dd",fillZero(d.getDate()));    
}  

//填充0    
function fillZero(value){    
	if(value.toString().length<2){    
	    return "0"+value;    
	}    
	return value;    
}    
//判空    
function checkNull(value){    
	if(!value||value==null||typeof(value) == "undefined"||value==""){    
	return true;    
	}    
	return false;    
}